import datetime
import xlrd
import pandas as pd
import numpy as np


# 方法一：
def binary_xlsx_pandas(binary_data:bytes):
    """
    处理二进制数据，并且添加列
    :param binary_data: 二进制数据
    :return: 
    """
    old_excel = xlrd.open_workbook(file_contents=binary_data)
    sheet = old_excel.sheets()[0]
    ds = [sheet.row_values(x) for x in range(0, sheet.nrows)]
    df = pd.DataFrame(ds[1:],columns=ds[0])
    df.loc[:, '数据时间'] = datetime.datetime.now().strftime('%Y-%m-%d') # 添加列
    df.to_excel('1.xlsx', index=False)


# 方法二：
def binary_xlsx(binary_data:bytes):
    old_excel = xlrd.open_workbook(file_contents=binary_data)
    sheet = old_excel.sheets()[0]
    new_excel = copy(old_excel)
    i = 1
    for row in sheet.get_rows():
        ws = new_excel.get_sheet(0)
        ws.write(0, 7, '时间')
        ws.write(i -1, 7, '2023/04/14')
        new_excel.save('excel.xls')
        old_excel = xlrd.open_workbook('excel.xls')
        new_excel = copy(old_excel)
        i = i+1